﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using ByteSite.Common;
using SqlSugar;

namespace ByteSite.BLL
{
    /// <summary>
    ///商品规格
    /// </summary>
    public partial class article_spec
    {
        private readonly Entitys.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息
        private readonly DAL.article_spec dal;
        private readonly DAL.Data data;

        public article_spec()
        {
            data = new DAL.Data();
            dal = new DAL.article_spec(sysConfig.sysdatabaseprefix);
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return data.Exists<Entitys.dt_article_spec>(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Entitys.dt_article_spec model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Entitys.dt_article_spec model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entitys.dt_article_spec GetModel(int id)
        {
            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public List<Entitys.dt_article_spec> GetList(int top, Expression<Func<Entitys.dt_article_spec, bool>> whereExpression, string filedOrder)
        {
            return data.List<Entitys.dt_article_spec>(top, whereExpression, filedOrder);
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public List<Entitys.dt_article_spec> GetList(int pageSize, int pageIndex, Expression<Func<Entitys.dt_article_spec, bool>> whereExpression, string filedOrder, out int recordCount)
        {
            return data.List<Entitys.dt_article_spec>(pageSize, pageIndex, whereExpression, filedOrder, out recordCount);
        }
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 返回栏目规格列表
        /// </summary>
        public List<Entitys.dt_article_spec> GetCategorySpecList(int category_id)
        {
            return dal.GetCategorySpecList(category_id);
        }

        public bool UpdateField(Expression<Func<Entitys.dt_article_spec, Entitys.dt_article_spec>> expression, Expression<Func<Entitys.dt_article_spec, bool>> whereExpression)
        {
            return data.UpdateColumns<Entitys.dt_article_spec>(expression, whereExpression);
        }
        #endregion
    }
}